Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
tiny-emitter
Advanced tools
The tiny-emitter package is a lightweight event emitter and listener library. It allows you to create an object that can emit events and have listeners that respond to those events. This is useful for creating a simple pub-sub or observer pattern implementation without the overhead of larger libraries.
Event Emission
Emitting events with optional data. Listeners for that event will be invoked.
const Emitter = require('tiny-emitter');
let emitter = new Emitter();
emitter.emit('event', 'some data');
Event Listening
Adding a listener for an event. The listener will be called whenever the specified event is emitted.
const Emitter = require('tiny-emitter');
let emitter = new Emitter();
emitter.on('event', function(data) {
console.log(data);
});
One-time Event Listening
Adding a one-time listener for an event. The listener will be invoked only the first time the event is emitted.
const Emitter = require('tiny-emitter');
let emitter = new Emitter();
emitter.once('event', function(data) {
console.log(data);
});
Removing Event Listeners
Removing a specific listener from an event.
const Emitter = require('tiny-emitter');
let emitter = new Emitter();
function listener(data) {
console.log(data);
}
emitter.on('event', listener);
emitter.off('event', listener);
EventEmitter3 is a high performance EventEmitter. It has a similar API to tiny-emitter but is optimized for performance and has no dependencies.
Wolfy87's EventEmitter is an implementation of the EventEmitter module found in Node.js but for the browser. It offers additional features like namespacing events, but it's larger in size compared to tiny-emitter.
Mitt is a tiny functional event emitter/listener with a similar scope to tiny-emitter but with an even smaller footprint and no class syntax. It's ES6 module compatible and can be a good alternative for those who prefer functional paradigms.
A tiny (less than 1k) event emitter library.
npm install tiny-emitter --save
var Emitter = require('tiny-emitter');
var emitter = new Emitter();
emitter.on('some-event', function (arg1, arg2, arg3) {
//
});
emitter.emit('some-event', 'arg1 value', 'arg2 value', 'arg3 value');
Alternatively, you can skip the initialization step by requiring tiny-emitter/instance
instead. This pulls in an already initialized emitter.
var emitter = require('tiny-emitter/instance');
emitter.on('some-event', function (arg1, arg2, arg3) {
//
});
emitter.emit('some-event', 'arg1 value', 'arg2 value', 'arg3 value');
Subscribe to an event
event
- the name of the event to subscribe tocallback
- the function to call when event is emittedcontext
- (OPTIONAL) - the context to bind the event callback toSubscribe to an event only once
event
- the name of the event to subscribe tocallback
- the function to call when event is emittedcontext
- (OPTIONAL) - the context to bind the event callback toUnsubscribe from an event or all events. If no callback is provided, it unsubscribes you from all events.
event
- the name of the event to unsubscribe fromcallback
- the function used when binding to the eventTrigger a named event
event
- the event name to emitarguments...
- any number of arguments to pass to the event subscribersBuild (Tests, Browserifies, and minifies)
npm install
npm run build
Test
npm install
npm test
FAQs
A tiny (less than 1k) event emitter library
The npm package tiny-emitter receives a total of 2,090,065 weekly downloads. As such, tiny-emitter popularity was classified as popular.
We found that tiny-emitter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.